package cc.bluemc.modules.weixin.service;


import cc.bluemc.modules.weixin.entity.WxQrcordScanEntity;
import cc.bluemc.platform.comm.DataTablesPagination;
import cc.bluemc.platform.jdbctemplatetool.JdbcTemplateTool;
import cc.bluemc.platform.jdbctemplatetool.exception.NoColumnAnnotationFoundException;
import cc.bluemc.platform.jdbctemplatetool.exception.NoIdAnnotationFoundException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
*WxQrcordScan service
*/
@Transactional(readOnly=true)
@Service("wxQrcordScanService")
public class WxQrcordScanService {
   	private Log log = LogFactory.getLog(this.getClass());
	@Autowired
	private JdbcTemplateTool jdbcTemplateTool;

  
  	@Transactional(readOnly=false)
    public void save(WxQrcordScanEntity wxQrcordScan) throws Exception{
    	jdbcTemplateTool.save(wxQrcordScan);
    }
	@Transactional(readOnly=false)
    public int saveAndGetId(WxQrcordScanEntity wxQrcordScan) throws Exception{
    	return jdbcTemplateTool.save(wxQrcordScan,"id");
    }
	@Transactional(readOnly=false)
    public void update(WxQrcordScanEntity wxQrcordScan) throws Exception{
    	jdbcTemplateTool.update(wxQrcordScan);
    }
	@Transactional(readOnly=false)
    public void saveOrUpdate(WxQrcordScanEntity wxQrcordScan) throws Exception {
        if (null == wxQrcordScan.getId() || 0 == wxQrcordScan.getId()) {
            save(wxQrcordScan);
        } else {
            update(wxQrcordScan);
        }
    }

    public WxQrcordScanEntity get(Integer id) throws NoIdAnnotationFoundException, NoColumnAnnotationFoundException{
    	return jdbcTemplateTool.get(WxQrcordScanEntity.class, id);
    }
 	/**
     * 所有列表
     */
    public List<WxQrcordScanEntity> getAll() {
    	String sql="SELECT * FROM t_wx_qrcord_scan ";
    	return jdbcTemplateTool.list(sql, null, WxQrcordScanEntity.class);
    }
    /**
     * 分页列表
     * @param page
     * @return
     */
    public DataTablesPagination getListOfPage(DataTablesPagination page,WxQrcordScanEntity wxQrcordScan){
    	StringBuffer sql = new StringBuffer(" FROM t_wx_qrcord_scan WHERE 1=1");
    	List<Object> params = new ArrayList<Object>();
    	
    	int count =jdbcTemplateTool.count("SELECT count(0)"+sql, params.toArray());
    	page.setiTotalRecords(count);
    	
    	sql.append(" LIMIT ?,?");
    	params.add(page.getiDisplayStart());
    	params.add(page.getiDisplayLength());
    	List<WxQrcordScanEntity> list = jdbcTemplateTool.list("SELECT * "+sql, params.toArray(), WxQrcordScanEntity.class);
    	page.setData(list);
    	return page;
    }
     /**
     * 删除
     * @throws Exception
     */
	@Transactional(readOnly=false)
    public void delete(WxQrcordScanEntity wxQrcordScan) throws Exception {
   	 	jdbcTemplateTool.delete( wxQrcordScan);
    }
}
